"""
    合并同一文件夹下多个excel
"""
# -*- coding: utf-8 -*-
import os
import openpyxl

from openpyxl import Workbook

result_file = 'D:\\02_item\\02_学位申请\\04_2024秋\\temp\\new.xlsx'
path = 'D:\\02_item\\02_学位申请\\04_2024秋\\temp\\'

if __name__ == '__main__':
    # 生成新的excel文档
    new_workbook = Workbook()
    new_sheet = new_workbook.active

    # 遍历文件夹中的所有文件
    for file_a in os.listdir(path):
        add_list = []
        # 检查文件扩展名是否为xlsx或xls
        if file_a.endswith('.xlsx') or file_a.endswith('.xls'):
            workbook = openpyxl.load_workbook(os.path.join(path, file_a))
            sheet = workbook.active
            # 指定第三行
            for cell in sheet[3]:
                row_data = cell.value
                add_list.append(row_data)
            # 追加列表
            new_sheet.append(add_list)

    # 本地保存
    new_workbook.save("D:/02_item/02_学位申请/04_2024秋/temp/2.xlsx")
